package com.cc.visitor.controller;

import com.cc.alltype.ResponseResult;
import com.cc.visitor.dao.LoginQrLogMapper;
import com.cc.visitor.entity.LoginQrLog;
import com.cc.visitor.service.LoginQrLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author chanchaw
 * @create 2024-12-11 15:28
 */
@CrossOrigin
@RestController
@RequestMapping("/loginQrLog")
public class LoginQrLogController {
    @Autowired
    private LoginQrLogMapper dao;
    @Autowired
    private LoginQrLogService service;

    /**
     * 判断一个UUID是否有微信用户登录过了
     * @param uuid
     * @return
     */
    @PostMapping("/isLoggedSimple/{uuid}")
    public ResponseResult isLoggedSimple(@PathVariable String uuid){
        List<LoginQrLog> loginQrLogs = Optional.ofNullable(dao.selectLoggedIn(uuid)).orElse(new ArrayList<>());
        Boolean isLoggedIn = loginQrLogs.size() == 0 ? false : true;
        return ResponseResult.ok(isLoggedIn);
    }
    @PostMapping("/isLogged/{uuid}")
    public ResponseResult isLogged(@PathVariable String uuid){
        return ResponseResult.ok(service.isLogged(uuid));
    }
    @PostMapping("/clearMsg/{uuid}")
    public ResponseResult clearMsg(@PathVariable String uuid){
        return ResponseResult.ok(service.clearMsg(uuid));
    }
}
